package com.heima.wemedia.admin;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.SensitiveDto;
import com.heima.model.wemedia.pojos.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @Author: JW
 * @Description: TODO
 * @DateTime: 2022-02-18 19:09
 **/
@RestController
@RequestMapping("/api/v1/sensitive")
public class SensitiveController {


    @Autowired
    private WmSensitiveService wmSensitiveService;

    @PostMapping("/list")
    public PageResponseResult find(@RequestBody SensitiveDto sensitiveDto){

        return wmSensitiveService.find(sensitiveDto);
    }


    /**
     * @Author: JW
     * @Description:  TODO 删除
     * @Date: 20:12 2022-02-18
     * @Param: [id]
     * @return: com.heima.model.common.dtos.ResponseResult
    **/
    @DeleteMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Integer id){

        wmSensitiveService.removeById(id);

        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /**
     * @Author: JW
     * @Description:  TODO 保存敏感词
     * @Date: 20:22 2022-02-18
     * @Param: [wmSensitive]
     * @return: com.heima.model.common.dtos.ResponseResult
    **/
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmSensitive wmSensitive){

        wmSensitive.setCreatedTime(new Date());

        wmSensitiveService.save(wmSensitive);

        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }


    /**
     * @Author: JW
     * @Description:  TODO 修改
     * @Date: 20:23 2022-02-18
     * @Param: []
     * @return: com.heima.model.common.dtos.ResponseResult
    **/
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmSensitive wmSensitive){

        wmSensitive.setCreatedTime(new Date());

        wmSensitiveService.updateById(wmSensitive);

        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
